#coding=utf-8

from django.db import models

class Campaign(models.Model):
  name = models.CharField( blank=False, null=False, unique=True, max_length=50)
  description = models.TextField()
  
  def __unicode__(self):
    return self.name
 
class Resource(models.Model):
  name = models.CharField( blank=False, null=False, unique=True, max_length=50)
  url = models.CharField( blank=False, null=False, unique=True, max_length=1000)
  created_at = models.DateTimeField( auto_now_add=True)
  camps = models.ManyToManyField('Campaign')
  times = models.IntegerField(default=0)
  
  def __unicode__(self):
    return self.name
    
class Person(models.Model):
  own_id = models.CharField( blank=False, null=False, unique=True, max_length=50)
  name = models.CharField(max_length=100)
  email = models.EmailField()
  
  def __unicode__(self):
    return self.own_id

class AccessRecord(models.Model):
  p = models.ForeignKey('Person')
  r = models.ForeignKey('Resource')
  acessed_at = models.DateTimeField( auto_now_add=True)
  
  def __unicode__(self):
    return '%s-->%s'%(self.p.own_id, self.r.name)
  
